<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
    <meta http-equiv="content-language" content="zh-CN" />
    

    
    <meta name="viewport" content="width=device-width, initial-scale=0.5">
    

    
    <title>R语言发邮件--mailR包</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
    
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">

    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css">

    <link rel="stylesheet" href="/css/stylesheet.css">
    <link rel="stylesheet" href="/css/home.css">

    
    
        <style type="text/css">
        body { background-color: #fbf6ec;}
        </style>
    
    
                
        
        
            <link rel="stylesheet" href="/css/main.css"/>
        




        
        
        
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/github.min.css"  />
         
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/highlight.min.js"></script>
        
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/r.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/yaml.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/latex.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/matlab.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/mathematica.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/julia.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/julia-repl.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/powershell.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/bash.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/shell.min.js"></script>
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/languages/python.min.js"></script>
        
        <script>hljs.initHighlightingOnLoad();</script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
     
     
</head>


<body>
    <script>
        window.addEventListener("resize", resizeThrottler, false);

        var resizeTimeout;
        function resizeThrottler() {
        
        if ( !resizeTimeout ) {
            resizeTimeout = setTimeout(function() {
            resizeTimeout = null;
            actualResizeHandler();
        
            
            }, 66);
        }
        }
        actualResizeHandler()
        function actualResizeHandler() {
                if (/mobile/i.test(navigator.userAgent) || /android/i.test(navigator.userAgent))
                {
                    document.body.classList.add('mobile');
                }else{
                    document.body.classList.remove('mobile');  
                }
    }</script>

    
      
      
            <nav class="navbar navbar-default navbar-static-top" style="opacity: .9" role="navigation">
        <div class="container-fluid">
            
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">

                    <span class="sr-only">Toggle navigation</span>
                    <span class="big-icon icon-bar"></span>
                    <span class="big-icon icon-bar"></span>
                    <span class="big-icon icon-bar"></span>

                </button>
                <a class="navbar-brand" href="/">zsc</a>
            </div>

            <div class="navbar-collapse collapse" id="bs-example-navbar-collapse-1" style="height: auto;">
                <ul class="nav navbar-nav navbar-right" style="font-size: 100%">
                    
                        
                            
                            <li class=""><a href="/about/">About</a></li>
                            
                            <li class=""><a href="/categories/">Categories</a></li>
                            
                            <li class=""><a href="/">Home</a></li>
                            
                            <li class=""><a href="/tags/">Tags</a></li>
                            
                            <li class=""><a href="/issue/">存在的问题</a></li>
                            
                        
                    
                </ul>
            </div>
        </div>
    </nav>







<div class = "div-content" id='div-content-my' style='display: none;' >
    

    <div class = 'inner-left' id= 'divTableOfContents' style="position:fixed;z-index:999;height: 55%;overflow: scroll;bottom: 5%;width: 22%;top: 25%" >
            <p class="slide slidemy" align = "center">
                <a href="javascript:hidediv();" id="strHref" class="btn-slide">目录收起-</a>
            </p>
            
            <div id="divtocTableOfContents">
            <nav id="TableOfContents">
  <ul>
    <li><a href="#mailr-包参数">mailR 包参数</a></li>
    <li><a href="#163-邮箱">163 邮箱:</a></li>
    <li><a href="#qq-邮箱">QQ 邮箱:</a></li>
  </ul>
</nav>
            </div>
    </div>
</div>
<script>  
    $(document).ready(function () {
    var demo = $("#divtocTableOfContents").find("a").length;
    if(demo > 2){
        $("div#div-content-my").fadeIn("slow");
    }
        
        
        
        
        
        
        
        
    }); 
</script>  









<div class="inner">
    



    <div class="blog-post">
        
                <div>
            <h2 align="center" id = "singe-h2">
                R语言发邮件--mailR包
                <time>
                    <br>
                    <span> 
                        <i class="fa fa-user-edit" style="color:#888;font-size: 80%;"></i>
                        zsc 
                    </span>
                    &nbsp 
                    <span>                 
                        <i class="fa fa-calendar-alt" style="color:#888;font-size: 80%;"></i>
                        2018-11-13 
                    </span>
                </time>
                
                
                <div>
                    <ul class="tags">
                        
                        <span>标签:</span>
                        <li><a class="link" href="/tags/r"> #r </a></li>
                        
                        <span> </span>
                        
                    </ul>
                    
                </div>
            </h2>
        </div>
    
        
        <section id="content">
            <p>亲测试邮箱为163邮箱 和QQ邮箱</p>
<h2 id="mailr-包参数">mailR 包参数</h2>
<p>mailR 包中只有一个接口函数&mdash;send.mail ,该包依恋java环境，请首先配置该环境，下面是该函数的一些基本参数：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-R" data-lang="R"><span style="display:flex;"><span><span style="color:#a6e22e">send.mail</span>(from, to, subject <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>, body <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>, encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;iso-8859-1&#34;</span>,
</span></span><span style="display:flex;"><span>  html <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, inline <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, smtp <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(), authenticate <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>,
</span></span><span style="display:flex;"><span>  send <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>, attach.files <span style="color:#f92672">=</span> <span style="color:#66d9ef">NULL</span>, debug <span style="color:#f92672">=</span> <span style="color:#66d9ef">FALSE</span>, <span style="color:#66d9ef">...</span>)
</span></span></code></pre></div><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>from</td>
<td>发件人邮箱</td>
</tr>
<tr>
<td>to</td>
<td>收件人邮箱</td>
</tr>
<tr>
<td>subject</td>
<td>邮件标题</td>
</tr>
<tr>
<td>body</td>
<td>邮件的内容(正文),内容可以是文本也可以是html网页格式</td>
</tr>
<tr>
<td>html</td>
<td>一个bool值，是否应该讲邮箱正文解析为HTML</td>
</tr>
<tr>
<td>inline</td>
<td>一个bool值，HTML文件中的图像是否应该被嵌入</td>
</tr>
<tr>
<td>smtp</td>
<td>重要的参数，设置服务器参数用的</td>
</tr>
<tr>
<td>authenticate</td>
<td>是否应该使用smtp中的参数</td>
</tr>
<tr>
<td>attach.files</td>
<td>指定相应的附件，若是多个则用字符向量表示</td>
</tr>
<tr>
<td>file.names</td>
<td>（省略参数），对相应的附件进行重命名</td>
</tr>
<tr>
<td>debug</td>
<td>你是否要查看详细的调试信息</td>
</tr>
</tbody>
</table>
<h2 id="163-邮箱">163 邮箱:</h2>
<p>如果发送频率过快，容易被封号，暂时发布出去了，只有等解封以后再发,</p>
<p><strong>注意</strong>： 在测试的时候，尽量写的和平时邮件一样的格式，不然会被认为是垃圾邮件</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-R" data-lang="R"><span style="display:flex;"><span><span style="color:#a6e22e">library</span>(mailR)
</span></span><span style="display:flex;"><span>sender <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;********@163.com&#34;</span>  <span style="color:#75715e"># 发件人</span>
</span></span><span style="display:flex;"><span>recipients <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;******@qq.com&#34;</span>) <span style="color:#75715e"># 收件人，可以多个</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">send.mail</span>(from <span style="color:#f92672">=</span> sender,
</span></span><span style="display:flex;"><span>          to <span style="color:#f92672">=</span> recipients,
</span></span><span style="display:flex;"><span>          subject <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Program Done.&#34;</span>,
</span></span><span style="display:flex;"><span>          body <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;My program is finished.&#34;</span>,
</span></span><span style="display:flex;"><span>          smtp <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>( 
</span></span><span style="display:flex;"><span>            host.name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;smtp.163.com&#34;</span>,  <span style="color:#75715e"># 163邮箱的服务器地址</span>
</span></span><span style="display:flex;"><span>            port <span style="color:#f92672">=</span> <span style="color:#ae81ff">465</span>,
</span></span><span style="display:flex;"><span>            user.name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;********@163.com&#34;</span>,
</span></span><span style="display:flex;"><span>            passwd <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;*********&#34;</span>, <span style="color:#75715e"># 这个是授权码而非密码</span>
</span></span><span style="display:flex;"><span>            ssl <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
</span></span><span style="display:flex;"><span>            tls <span style="color:#f92672">=</span><span style="color:#66d9ef">TRUE</span>), 
</span></span><span style="display:flex;"><span>          encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;utf-8&#34;</span>,
</span></span><span style="display:flex;"><span>          authenticate <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
</span></span><span style="display:flex;"><span>          send <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
</span></span></code></pre></div><p>报错：其中的信息：（表示发送的邮件过多）</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Caused by: com.sun.mail.smtp.SMTPSendFailedException: <span style="color:#ae81ff">554</span> DT:SPM <span style="color:#ae81ff">163</span> smtp2,DNGowAA3E32d1ONbg+8oAA--.78S2 1541657766,please see http://mail.163.com/help/help_spam_16.htm?ip<span style="color:#f92672">=</span>182.88.95.17&amp;hostid<span style="color:#f92672">=</span>smtp2&amp;time<span style="color:#f92672">=</span><span style="color:#ae81ff">1541657766</span>
</span></span></code></pre></div><h2 id="qq-邮箱">QQ 邮箱:</h2>
<p>QQ邮箱好像不存在发多了被封号的问题，我猜如果发到一定量，也应该会出现上述问题吧</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-R" data-lang="R"><span style="display:flex;"><span>sender <span style="color:#f92672">&lt;-</span> <span style="color:#e6db74">&#34;******@qq.com&#34;</span>
</span></span><span style="display:flex;"><span>recipients <span style="color:#f92672">&lt;-</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;*******@163.com&#34;</span>,<span style="color:#e6db74">&#34;*******@qq.com&#34;</span>) 
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">send.mail</span>(from <span style="color:#f92672">=</span> sender,
</span></span><span style="display:flex;"><span>          to <span style="color:#f92672">=</span> recipients,
</span></span><span style="display:flex;"><span>          subject <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;你好！我的朋友&#34;</span>,
</span></span><span style="display:flex;"><span>          body <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;第一次用程序写邮件!!哈哈&#34;</span>,
</span></span><span style="display:flex;"><span>          smtp <span style="color:#f92672">=</span> <span style="color:#a6e22e">list</span>(
</span></span><span style="display:flex;"><span>            host.name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;smtp.qq.com&#34;</span>, <span style="color:#75715e">## QQ邮箱的服务器地址</span>
</span></span><span style="display:flex;"><span>            port <span style="color:#f92672">=</span> <span style="color:#ae81ff">465</span>,
</span></span><span style="display:flex;"><span>            user.name <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;********@qq.com&#34;</span>,
</span></span><span style="display:flex;"><span>            passwd <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;*********&#34;</span>, <span style="color:#75715e">## 这个是授权码而非密码</span>
</span></span><span style="display:flex;"><span>            ssl <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>), 
</span></span><span style="display:flex;"><span>          encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;utf-8&#34;</span>,
</span></span><span style="display:flex;"><span>          authenticate <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>,
</span></span><span style="display:flex;"><span>          attach.files <span style="color:#f92672">=</span><span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;./bbbb.xlsx&#34;</span>,<span style="color:#e6db74">&#34;01_hellworld.cpp&#34;</span>), <span style="color:#75715e">#附件</span>
</span></span><span style="display:flex;"><span>          file.names <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>(<span style="color:#e6db74">&#34;aaa&#34;</span>,<span style="color:#e6db74">&#34;bbb&#34;</span>), <span style="color:#75715e"># 对附件进行重命名</span>
</span></span><span style="display:flex;"><span>          file.descriptions <span style="color:#f92672">=</span> <span style="color:#a6e22e">c</span>( <span style="color:#e6db74">&#34;xlsx 文件&#34;</span>,<span style="color:#e6db74">&#34;c++文件作业&#34;</span>),<span style="color:#75715e"># 附件的说明</span>
</span></span><span style="display:flex;"><span>          send <span style="color:#f92672">=</span> <span style="color:#66d9ef">TRUE</span>)
</span></span></code></pre></div>
        </section>
    </div>
    <br>
    
    




<span id="/md/2018-11-13-%E5%8F%91%E9%82%AE%E4%BB%B6mailr%E5%8C%85/" class="leancloud_visitors" data-flag-title="R语言发邮件--mailR包">
  <span class="post-meta-item-text">文章总阅读量 </span>
  <span class="leancloud-visitors-count"><i class="leancloud-visitors-count"></i></span>次;
  <p></p>
</span>



    

    
    
    <button id="edit-button" class="icon-button" type="button" title="Fork and edit" aria-label="Fork and edit" aria-haspopup="true" aria-expanded="false" aria-controls="edit">
        <i class="fa fa-edit">编辑本文</i>
    </button>
    
    
    

    <br>
    <hr>
    <li style="float:left;list-style:none">
        
        <a class="previous" href="/md/2018-11-06-githubdesktop%E6%9D%83%E9%99%90%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/"> 上一篇: GitHubDesktop权限问题解决办法</a>
        
    </li>
    <li style="float:right;list-style:none">
        
        <a class="next" href="/md/2018-11-17-%E9%87%8D%E8%A3%85%E7%B3%BB%E7%BB%9F%E5%90%8E%E7%9A%84%E5%B8%B8%E7%94%A8%E5%B7%A5%E5%85%B7/"> 下一篇: 重装系统后一些有用的激活工具</a>
        
    </li>
     
    
    <script src="/js/copyCode.js"></script>
    <script src="/js/tooltips.js"></script>
    
   
    <script>
    [].slice.call(document.querySelectorAll('table')).forEach(function(el) {
        var wrapper = document.createElement('div');
        wrapper.className = 'table-area';
        el.parentNode.insertBefore(wrapper, el);
        el.parentNode.removeChild(el);
        wrapper.appendChild(el);
        $("table").wrap("<div class='table-area'></div>");
    })
    </script>

    
<br>
<hr>


<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-111691389-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  gtag('js', new Date());

  gtag('config', 'UA-111691389-1');
</script>




      
      
      

       
      
      
      <script>
              document.getElementById("edit-button").addEventListener("click", function () {
                  var editWindow = window.open("https:\/\/github.com\/zoushucai\/blogmmm/edit/master/content/md\/2018-11-13-发邮件mailR包.md");
              });</script>
      
          




<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  } 
</script>



    </style>
    <script type="text/javascript">
    function showdiv(){
        document.getElementById("divtocTableOfContents").style.display="block";
        document.getElementById("strHref").innerHTML="目录收起-";
        document.getElementById('divTableOfContents').style.width="22%";
        document.getElementById('divTableOfContents').style.height="55%";
        document.getElementById('divTableOfContents').style.top="25%";
        document.getElementById('divTableOfContents').style.bottom="5%";
        document.getElementById("strHref").href="javascript:hidediv()";
    }
    function hidediv(){
        document.getElementById("divtocTableOfContents").style.display="none";
        document.getElementById("strHref").innerHTML="目录展开+";
        document.getElementById("strHref").href="javascript:showdiv()";
        document.getElementById('divTableOfContents').style.width="10%";
        document.getElementById('divTableOfContents').style.height="5%";
    }
    </script>
</body>

</html>
</div> 







    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/mathtex-script-type.min.js" integrity="sha384-LJ2FmexL77rmGm6SIpxq7y+XA6bkLzGZEgCywzKOZG/ws4va9fUVu2neMjvc3zdv" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"></script>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            renderMathInElement(document.body, {
            delimiters: [
                            {left: "$$", right: "$$", display: true},
                            {left: "$", right: "$", display: false},
                            {left: "\\(", right: "\\)", display: false},
                            {left: "\\[", right: "\\]", display: true}
                        ]
            });
        });
    </script>













<br>
<div class="inner">
              
            
          
          
  
          
  
  <div id="vcomments"></div>
  
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  
  <script src='//unpkg.com/valine/dist/Valine.min.js'></script>
  <script type="text/javascript">
    new Valine({
        el: '#vcomments' ,
        appId: 'HfHPKPkLa0cBEDPcdBAHuqMv-gzGzoHsz',
        appKey: 'r5RJAasN8e0mB9sq6y9pEcX0',
        lang:'zh-CN',
        notify:  false , 
        verify:  false  ,
        avatar:'identicon', 
        placeholder: '说点什么吧...',
        visitor:  true 
    });
  </script>

</div>

<br>
<br>
<footer>
    <p style="float:right;margin-right: 5%;margin-top: 0%;">
        &copy; 2022 <a href="https://github.com/zoushucai">zsc</a>
      </p>
</footer>
<br>
<br>


